var $strAcademicoCobrosCobrosUrl = "admin_academico_cobros_cobros_data.php";
var $strAcademicoCobrosCobrosForm = "frmAcademicoCobrosCobros";
var intAcademicoCobrosCobrosCorrelativo = 0;

function fntAnularCobro(idCobro) {
    $.ajax({
        type: "POST",
        data: "idCobro="+idCobro,
        url: $strAcademicoCobrosCobrosUrl+"?operation=fntAnularCobro",
        beforeSend:function() {
            fntOpenDialogCargando();
        },
        success:function(data) {            
            fntCloseDialogCargando();
            $("#contenidocobrosanulacion").dialog("close");
            $("#contenidocobrosanulacion").remove();
            alert(data);            
            fntAcademicoCobrosCobrosContenido();
        },
        error:function() {
            fntCloseDialogCargando();
        }
    });    
}

function fntShowDetalleAnulacion(idCobro) {        
    var objInterface = $("#windatoscobro");
    objInterface.html("");
    $("#contenidocobrosanulacion").dialog("close");
    $.ajax({
        type: "POST",
        data: "idCobro="+idCobro,
        url: $strAcademicoCobrosCobrosUrl+"?operation=fntShowDetalleAnulacion",
        beforeSend:function() {
            fntOpenDialogCargando();
        },
        success:function(data) {
            objInterface.html(data);
            fntCloseDialogCargando();
            $("#contenidocobrosanulacion").dialog({
                modal:true,
                title:"Datos Cobro"
            });
            $("button").button();
        },
        error:function() {
            fntCloseDialogCargando();
        }
    });    
}

function fntAcademicoCobrosCobrosFiltro() {
    
    var objInterface = $("#divAcademicoCobrosCobrosFiltro");
    objInterface.html("");
    $.ajax({

        type: "POST",
        data: $("#"+$strAcademicoCobrosCobrosForm).serialize(),
        url: $strAcademicoCobrosCobrosUrl+"?operation=filtro",
        beforeSend:function() {
            fntOpenDialogCargando();
        },
        success:function(data) {
            objInterface.html(data);
            fntCloseDialogCargando();
        },
        error:function() {
            fntCloseDialogCargando();
        }

    });
    
}
function fntAcademicoCobrosCobrosContenido() {    
    var objInterface = $("#divAcademicoCobrosCobrosContenido");
    objInterface.html("");
    
    $.ajax({
        type: "POST",
        data: $("#"+$strAcademicoCobrosCobrosForm).serialize(),
        url: $strAcademicoCobrosCobrosUrl+"?operation=contenido",
        beforeSend:function() {
            fntOpenDialogCargando();
        },
        success:function(data) {
            objInterface.html(data);
            
            fntCloseDialogCargando();
        },
        error:function() {
            fntCloseDialogCargando();
        }

    });
    
}
function fntAcademicoCobrosCobrosContenidoDetalle() {
    
    var objInterface = $("#divAcademicoCobrosCobrosContenidoDetalle");
    objInterface.html("");
    $.ajax({

        type: "POST",
        data: $("#"+$strAcademicoCobrosCobrosForm).serialize(),
        url: $strAcademicoCobrosCobrosUrl+"?operation=contenidoDetalle",
        beforeSend:function() {
            fntOpenDialogCargando();
        },
        success:function(data) {
            objInterface.html(data);
            fntCloseDialogCargando();
        },
        error:function() {
            fntCloseDialogCargando();
        }

    });
    
}
function fntAcademicoCobrosCobrosAgregar() {
    
    objTabla = $("#tblAcademicoCobrosCobrosContenidoDetalle");
    strTipo = $("select[name='sltAcademicoCobrosCobrosTipo']").val();
    sinValor = $("input[name='txtAcademicoCobrosCobrosValor']").val();
    strNoDocumento = $("input[name='txtAcademicoCobrosCobrosNoDocumento']").val();
    strFecha = $("input[name='txtAcademicoCobrosCobrosFecha']").val();
    
    if( sinValor > 0 ) {
        intAcademicoCobrosCobrosCorrelativo++;
        strHtml = '';
        strHtml += '<tr>';
        strHtml += '<td width="25%" align="center" style="border: 1px solid black;"><input type="hidden" name="hdnAcademicoCobrosCobrosTipo_'+intAcademicoCobrosCobrosCorrelativo+'" value="'+strTipo+'">'+strTipo+'</td>';
        strHtml += '<td width="25%" align="center" style="border: 1px solid black;"><input type="hidden" name="hdnAcademicoCobrosCobrosValor_'+intAcademicoCobrosCobrosCorrelativo+'" value="'+sinValor+'">'+sinValor+'</td>';
        strHtml += '<td width="25%" align="center" style="border: 1px solid black;"><input type="hidden" name="hdnAcademicoCobrosCobrosNoDocumento_'+intAcademicoCobrosCobrosCorrelativo+'" value="'+strNoDocumento+'">'+strNoDocumento+'</td>';
        strHtml += '<td width="25%" align="center" style="border: 1px solid black;"><input type="hidden" name="hdnAcademicoCobrosCobrosFecha_'+intAcademicoCobrosCobrosCorrelativo+'" value="'+strNoDocumento+'">'+strFecha+'</td>';
        strHtml += '<td width="25%" align="center" style="border: 1px solid black;">&nbsp;</td>';
        strHtml += '</tr>';
        objTabla.append(strHtml);
        
        $("select[name='sltAcademicoCobrosCobrosTipo']").val("DEPOSITO");
        $("input[name='txtAcademicoCobrosCobrosValor']").val("");
        $("input[name='txtAcademicoCobrosCobrosNoDocumento']").val("");
        $("input[name='txtAcademicoCobrosCobrosFecha']").val("");
    }
    
}
function fntAcademicoCobrosCobrosValidar() {
    strError = "";
    boolReturn = true;
    
    /*if( $("input[name='txtAcademicoCobrosCobros_fk-estudiante']").val() > 0 ) {
        strError += (strError!="")? "\n" : "";
        strError += "Seleccione catedratico";
        boolReturn = false;
    }
    if( $("input[name='txtAcademicoCobrosCobros_fk-periodo']").val() > 0 ) {
        strError += (strError!="")? "\n" : "";
        strError += "Seleccione periodo";
        boolReturn = false;
    }
    if( $("input[name='txtAcademicoCobrosCobros_fk-grado']").val() > 0 ) {
        strError += (strError!="")? "\n" : "";
        strError += "Seleccione grado";
        boolReturn = false;
    }
    if( $("input[name='txtAcademicoCobrosCobros_FECHA-ASIGNACION']").val().length == 0 ) {
        strError += (strError!="")? "\n" : "";
        strError += "Ingrese fecha de asignaci?n";
        boolReturn = false;
    }
    if( $("input[name='txtAcademicoCobrosCobros_VIGENCIA-INICIAL']").val().length == 0 ) {
        strError += (strError!="")? "\n" : "";
        strError += "Ingrese vigencia inicial";
        boolReturn = false;
    }
    if( $("input[name='txtAcademicoCobrosCobros_VIGENCIA-FINAL']").val().length == 0 ) {
        strError += (strError!="")? "\n" : "";
        strError += "Ingrese vigencia final";
        boolReturn = false;
    }*/
    
    if( !boolReturn )
        alert(strError);
        
    return boolReturn;
    
}
function fntAcademicoCobrosCobrosGrabar() {
    
    var objInterface = $("#divAcademicoCobrosCobrosOperaciones");
    objInterface.html("");
    if( fntAcademicoCobrosCobrosValidar() ) {
        $.ajax({

            type: "POST",
            data: $("#"+$strAcademicoCobrosCobrosForm).serialize(),
            url: $strAcademicoCobrosCobrosUrl+"?operation=s",
            beforeSend:function() {
                fntOpenDialogCargando();
            },
            success:function(data) {
                objInterface.html(data);
                fntCloseDialogCargando();
                fntAcademicoCobrosCobrosNuevo();
            },
            error:function() {
                fntCloseDialogCargando();
            }

        });
    }
    
}
function fntAcademicoCobrosCobrosNuevo() {
    
    var objInterface = $("#divAcademicoCobrosCobrosOperaciones");
    objInterface.html("");
    
    fntAcademicoCobrosCobrosFiltro();
    objInterface = $("#divAcademicoCobrosCobrosContenido");
    objInterface.html("");
	
// fntAcademicoCobrosCobrosContenido();  

}

$(function() {
    $("#btnAcademicoCobrosCobrosNuevo").click( function () {
        fntAcademicoCobrosCobrosNuevo();
    });
    $("#btnAcademicoCobrosCobrosGrabar").click( function () {
        fntAcademicoCobrosCobrosGrabar();
    });
    fntAcademicoCobrosCobrosFiltro();
});